<template>
	<view class="login">
		<view class="postx">
			<view :style="'height:'+statusBarHeight+'px'"></view>
			<view class="flexJusp" :style="'height:'+navigationBarHeight+'px;line-height:'+navigationBarHeight+'px'">
				<view @click="backs" style="width:100rpx;">
					<image style="width:20rpx;height:34rpx;margin:24rpx 0 0 24rpx;" src="/static/image/mv_tuichu.png">
					</image>
				</view>
				<view style="text-align: center;font-size: 36rpx;font-weight: bold;">登录</view>
				<view style="width:100rpx;"></view>
			</view>
		</view>
		<view :style="'height:'+statusBarHeight+'px'"></view>
		<view :style="'height:'+navigationBarHeight+'px'"></view>
		<view style="text-align: center;margin:240rpx 0 0;">
			<image style="width:174rpx;height:174rpx;border-radius:50%;" src="../../static/image/05_12wd.png"></image>
			<view style="margin:24rpx 0 76rpx;font-size: 36rpx;font-weight: bold;color: #000000;">上门服务小程序</view>
		</view>
		<!-- <view style="padding:32rpx 44rpx;width: 574rpx;background: #FFFFFF;border-radius: 60rpx;margin:auto;">
			<input v-model="tuima" type="number" maxlength="11" style="font-size: 30rpx;height:42rpx;"
				placeholder="请输入邀请码" />
		</view> -->
		<!-- 	<view class="flex" style="padding:32rpx 44rpx;width: 574rpx;background: #FFFFFF;border-radius: 60rpx;margin:40rpx auto 0;">
			<input style="font-size: 30rpx;height:42rpx;width:410rpx;" placeholder="请输入验证码"/>
			<view style="width: 160rpx;color: #2089FF;text-align: right;"><text v-if="isCode" @click="getCode">获取验证码</text><text v-else>{{time}}s</text></view>
		</view> -->
		<!-- <button type="default" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber">获取手机号</button> -->

		<view class="buttons" @click="logins">登录</view>
	</view>
</template>

<script>
	import {
		systemInfo
	} from '@/https/mixin.js'
	export default {
		mixins: [systemInfo],
		data() {
			return {
				time: 60,
				isCode: true,
				mobile: '',
				code: '',
				tuima: '',
				supId: '',
			};
		},
		onLoad(option) {
			uni.hideTabBar()
			this.getSystemInfo()
			this.supId = option.supId
			let openId = uni.getStorageSync('openId')
			if (this.supId && openId) {
				uni.switchTab({
					url: '/pages/index/index'
				})
				return
			}
		},
		methods: {
			decryptPhoneNumber(e) {
				this.$httpapi('getPhone', 'POST', {
					encryptedData: e.detail.encryptedData,
					iv: e.detail.iv,
					code: e.detail.code
				}).then(res => {

				})
				console.log(e, '-----------')
			},
			backs() {
				uni.navigateBack()
			},
			getCode() {
				if (this.mobile == '') return this.$utils.showtt('请输入手机号')
				if (!this.$utils.isMobile.test(this.mobile)) return this.$utils.showtt('手机号格式不正确')
				let params = {
					account: this.mobile,
					event: 'event'
				}
				if (this.isCode) {
					// this.$httpapi('User/sendCode', 'POST', params).then(res => {
					// this.$utils.showtt(res.msg)
					this.isCode = false
					let timer = setInterval(() => {
						this.time--
						if (this.time == 0) {
							this.isCode = true
							this.time = 60
							clearInterval(timer)
						}
					}, 1000)
					console.log(res, '--------')
					// })
				}
			},
			logins() {
				var that = this
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						console.log(loginRes, '------------')
						that.$httpapi('getOpenid', 'POST', {
							code: loginRes.code
						}).then(res => {
							uni.setStorageSync('openId', res.data)
							that.loginx(res.data)
							// if(res.code==200){
							// 	uni.navigateBack()
							// }
							// that.register(res.data.openid)
						})
					},
					fail: function(err) {
						// 登录授权失败  
						// err.code是错误码
					}
				});

			},
			loginx(code) {
				this.$httpapi('empowerlogin', 'POST', {
					supId: this.supId
				}).then(res => {
					uni.setStorageSync('openId', res.data.openid)
					if (res.code == 200) {
						if (this.supId) {
							uni.switchTab({
								url: '/pages/index/index'
							})
						} else {
							uni.navigateBack()
						}
					}
					// that.register(res.data.openid)
				})
			}
		}
	}
</script>

<style lang="scss">
	.login {
		min-height: 100vh;
		width: 750rpx;
		background: linear-gradient(190deg, #CCEAFF, #F5F6FA);

		.postx {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99999999;
		}

		.buttons {
			margin: 200rpx auto 0;
			text-align: center;
			width: 650rpx;
			height: 98rpx;
			background: linear-gradient(180deg, #2089FF 0%, #11ACEF 100%);
			border-radius: 50rpx;
			font-size: 30rpx;
			color: #FFFFFF;
			line-height: 98rpx;
		}
	}
</style>